// NeLNS - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010  Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

#ifndef NELNS_CONFIG
#define NELNS_CONFIG ""
#endif // NELNS_CONFIG

#ifndef NELNS_LOGS
#define NELNS_LOGS ""
#endif // NELNS_LOGS

#include <nel/misc/types_nl.h>
#include <nel/misc/debug.h>
#include <nel/misc/config_file.h>
#include <nel/misc/displayer.h>
#include <nel/misc/command.h>
#include <nel/misc/log.h>
#include <nel/misc/window_displayer.h>
#include <nel/misc/path.h>


using namespace NLNET;

//
// Variables
//

// store specific user information
NLMISC::CFileDisplayer *Fd = NULL;
NLMISC::CStdDisplayer Sd;
NLMISC::CLog *Output = NULL;

//
// Callback array
//

TUnifiedCallbackItem ClientCallbackArray[] =
{

};

class CClientConsole : public IService
{
public:

	CClient (){ }

	void init ()
	{
		Output = new NLMISC::CLog;

		std::string fn = IService::getInstance()->SaveFilesDirectory;
		fn += "client_console.log";
		nlinfo("Client Console stat in directory '%s'", fn.c_str());
		Fd = new NLMISC::CFileDisplayer(fn);
		Output->addDisplayer (Fd);
		if (WindowDisplayer) Output->addDisplayer (WindowDisplayer);

		Output->displayNL ("Client initialized");

//		NLNET::CUnifiedNetwork::getInstance()->setServiceDownCallback("RS", cbRSDisconnection, NULL);


	}

	bool update ()
	{
		return true;
	}

	void release ()
	{
		Output->displayNL ("Client Console released");
	}
};

// Service instantiation
NLNET_SERVICE_MAIN (CClientConsole, "CC", "client_console", 0, ClientCallbackArray, NELNS_CONFIG, NELNS_LOGS);


//
// Variables
//

//
// Commands
//

NLMISC_COMMAND (shards, "displays the list of all registered shards", "")
{
	if(args.size() != 0) return false;

	//log.displayNL ("Display the %d registered shards :", Shards.size());
	//for (uint i = 0; i < Shards.size(); i++)
	//{
	//	log.displayNL ("* ShardId: %d SId: %d NbPlayers: %d", Shards[i].ShardId, Shards[i].SId.get(), Shards[i].NbPlayers);
	//	CUnifiedNetwork::getInstance()->displayUnifiedConnection (Shards[i].SId, &log);
	//}
	//log.displayNL ("End of the list");

	return true;
}
